//index.js
//获取应用实例


const fetch = require('../../utils/util.js');
const query = fetch.fetch;
const api = fetch.api;
// const formatTime = fetch.formatTime 
const app = getApp()

Page({
  data: {
    dataMsg: [],
  },
  //评分事件
  evclick: function (event) {
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.login({
      success: (res) => {
        let url = 'https://xiaochengxu.leanapp.cn/getCodeForOpenId/' + res.code
        const data = fetch.openid(url, 'get', null)
        data.then(data => {
          wx.setStorage({
            key: "openid",
            data: data.openid
          })
          //获取openID
          // wx.getStorage({
          //   key: 'openid',
          //   success: function (res) {
          //     console.log(res.data)
          //   }
          // })
          console.log(data.openid)
          const islogin = query(api.islogin + data.openid, 'get', null)
          islogin.then(data => {
            if (data === 2) {
              console.log(333,data)
              wx.reLaunch({
                url: '../login/logs'
              })
            } else if(data===1){
              wx.reLaunch({
                url: '../index/index'
              })
            }
          })
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
      wx.getStorage({
        key: 'openid',
        success: (res) => {
          const data = query(api.indexstar, 'post',
           { openId: res.data, 
            //  orderStatus: this.data.orderStatus,
             orderStatus:5
            });
          data.then(data => {
            console.log(data, 44456)
            this.setData({
              dataMsg: data
            })
          })

        }
      })
    },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})